package miku.firstgame.model.gold.util
{
	import miku.firstgame.model.gold.card.BombCard;
	import miku.firstgame.model.gold.card.Card;
	import miku.firstgame.model.gold.card.CardCanPassPosition;
	import miku.firstgame.model.gold.card.EndCard;
	import miku.firstgame.model.gold.card.GoldCardType;
	import miku.firstgame.model.gold.card.MapCard;
	import miku.firstgame.model.gold.card.RoadCard;
	import miku.firstgame.model.gold.card.ToolCard;
	import miku.firstgame.model.gold.card.ToolType;
	import miku.firstgame.model.gold.interfaces.ICard;
	import miku.firstgame.ui.card.CardUI;
	import miku.firstgame.ui.card.EndCardUI;
	import miku.firstgame.ui.card.RoadCardUI;
	import miku.firstgame.ui.card.ToolCardUI;

	public class CardUtil
	{
		public function CardUtil()
		{
		}

		public static function getCardUIByCard(card:ICard):CardUI
		{
			if (card is EndCard)
			{
				return new EndCardUI(card);
			}
			if (card is RoadCard)
			{
				return new RoadCardUI(card);
			}
			else if (card is ToolCard)
			{
				return new ToolCardUI(card);
			}
			else
			{
				return new CardUI(card);
			}
		}

		public static function parseCardByType(type:int):Card
		{
			if (type >= GoldCardType.TOP_LEFT_BOTTOM_RIGHT_CENTER && type <= GoldCardType.TOP_LEFT_BOTTOM_RIGHT)
			{
				var roadCard:RoadCard;
				roadCard = new RoadCard(type);
				switch (type)
				{
					case GoldCardType.TOP_LEFT_BOTTOM_RIGHT_CENTER:
						roadCard.passPosition = CardCanPassPosition.TOP
							| CardCanPassPosition.BOTTOM | CardCanPassPosition.LEFT
							| CardCanPassPosition.RIGHT | CardCanPassPosition.CENTER;
						break;
					case GoldCardType.TOP_LEFT_RIGHT_CENTER:
						roadCard.passPosition = CardCanPassPosition.TOP | CardCanPassPosition.LEFT
							| CardCanPassPosition.RIGHT | CardCanPassPosition.CENTER;
						break;
					case GoldCardType.TOP_LEFT_BOTTOM_CENTER:
						roadCard.passPosition = CardCanPassPosition.TOP
							| CardCanPassPosition.BOTTOM | CardCanPassPosition.LEFT
							| CardCanPassPosition.CENTER;
						break;
					case GoldCardType.LEFT_RIGHT_CENTER:
						roadCard.passPosition = CardCanPassPosition.LEFT
							| CardCanPassPosition.RIGHT | CardCanPassPosition.CENTER;
						break;
					case GoldCardType.TOP_BOTTOM_CENTER:
						roadCard.passPosition = CardCanPassPosition.TOP
							| CardCanPassPosition.BOTTOM | CardCanPassPosition.CENTER;
						break;
					case GoldCardType.TOP_LEFT_CENTER:
						roadCard.passPosition = CardCanPassPosition.TOP
							| CardCanPassPosition.LEFT | CardCanPassPosition.CENTER;
						break;
					case GoldCardType.TOP_RIGHT_CENTER:
						roadCard.passPosition = CardCanPassPosition.TOP
							| CardCanPassPosition.RIGHT | CardCanPassPosition.CENTER;
						break;
					case GoldCardType.LEFT:
						roadCard.passPosition = CardCanPassPosition.LEFT;
						break;
					case GoldCardType.TOP:
						roadCard.passPosition = CardCanPassPosition.TOP;
						break;
					case GoldCardType.TOP_LEFT:
						roadCard.passPosition = CardCanPassPosition.TOP
							| CardCanPassPosition.LEFT;
						break;
					case GoldCardType.TOP_RIGHT:
						roadCard.passPosition = CardCanPassPosition.TOP
							| CardCanPassPosition.RIGHT;
						break;
					case GoldCardType.TOP_BOTTOM:
						roadCard.passPosition = CardCanPassPosition.TOP
							| CardCanPassPosition.BOTTOM;
						break;
					case GoldCardType.LEFT_RICHT:
						roadCard.passPosition = CardCanPassPosition.LEFT
							| CardCanPassPosition.RIGHT;
						break;
					case GoldCardType.TOP_LEFT_RIGHT:
						roadCard.passPosition = CardCanPassPosition.TOP
							| CardCanPassPosition.LEFT | CardCanPassPosition.RIGHT;
						break;
					case GoldCardType.TOP_LEFT_BOTTOM:
						roadCard.passPosition = CardCanPassPosition.TOP
							| CardCanPassPosition.LEFT | CardCanPassPosition.BOTTOM;
						break;
					case GoldCardType.TOP_LEFT_BOTTOM_RIGHT:
						roadCard.passPosition = CardCanPassPosition.TOP
							| CardCanPassPosition.LEFT | CardCanPassPosition.BOTTOM
							| CardCanPassPosition.RIGHT;
						break;
				}
				return roadCard;
			}
			else if (type >= GoldCardType.TAKE_SHOVEL && type <= GoldCardType.GET_SHOVEL_LIGHT)
			{
				//var TODO
				var toolCard:ToolCard = new ToolCard(type);
				switch (type)
				{

					case GoldCardType.GET_CAR:
						toolCard.name = "车";
						toolCard.isDestroy = false;
						toolCard.toolType = ToolType.CAR;
						break;
					case GoldCardType.GET_CAR_LIGHT:
						toolCard.name = "车和灯";
						toolCard.isDestroy = false;
						toolCard.toolType = ToolType.CAR | ToolType.LIGHT;
						break;
					case GoldCardType.GET_CAR_SHOVEL:
						toolCard.name = "车和铲";
						toolCard.isDestroy = false;
						toolCard.toolType = ToolType.CAR | ToolType.SHOVEL;
						break;
					case GoldCardType.GET_LIGHT:
						toolCard.name = "灯";
						toolCard.isDestroy = false;
						toolCard.toolType = ToolType.LIGHT;
						break;
					case GoldCardType.GET_SHOVEL:
						toolCard.name = "铲";
						toolCard.isDestroy = false;
						toolCard.toolType = ToolType.SHOVEL;
						break;
					case GoldCardType.GET_SHOVEL_LIGHT:
						toolCard.name = "铲和灯";
						toolCard.isDestroy = false;
						toolCard.toolType = ToolType.SHOVEL | ToolType.LIGHT;
						break;
					case GoldCardType.TAKE_CAR:
						toolCard.name = "毁坏车";
						toolCard.isDestroy = true;
						toolCard.toolType = ToolType.CAR;
						break;
					case GoldCardType.TAKE_LIGHT:
						toolCard.name = "毁坏灯";
						toolCard.isDestroy = true;
						toolCard.toolType = ToolType.LIGHT;
						break;
					case GoldCardType.TAKE_SHOVEL:
						toolCard.name = "毁坏铲";
						toolCard.isDestroy = true;
						toolCard.toolType = ToolType.SHOVEL;
						break;

				}

				return toolCard;
			}
			else if (type == GoldCardType.BOMB)
			{
				var bombCard:Card = new BombCard(type);
				bombCard.name = "爆炸卡";
				return bombCard;
			}
			else if (type == GoldCardType.MAP)
			{
				var mapCard:Card = new MapCard(type);
				mapCard.name = "地图卡";
				return mapCard;
			}
			else
			{
				var card:Card = new Card(type);
				switch (type)
				{
					case GoldCardType.BAD_MAN:
						card.name = "坏人";
						break;
					case GoldCardType.BLANK:
						card.name = "空白卡";
						break;
					case GoldCardType.BOMB:
						card.name = "炸弹卡";
						break;
					case GoldCardType.END_DUMP:
						card.name = "假终点";
						break;
					case GoldCardType.END_GOLD:
						card.name = "真终点";
						break;
					case GoldCardType.GET_CAR:
						card.name = "车";
						break;
					case GoldCardType.GET_CAR_LIGHT:
						card.name = "车和灯";
						break;
					case GoldCardType.GET_CAR_SHOVEL:
						card.name = "车和铲";
						break;
					case GoldCardType.GET_LIGHT:
						card.name = "灯";
						break;
					case GoldCardType.GET_SHOVEL:
						card.name = "铲";
						break;
					case GoldCardType.GET_SHOVEL_LIGHT:
						card.name = "铲和灯";
						break;
					case GoldCardType.GOOD_MAN:
						card.name = "好人";
						break;
					case GoldCardType.MAP:
						card.name = "地图卡";
						break;
					case GoldCardType.START:
						card.name = "起始点";
						break;
					case GoldCardType.TAKE_CAR:
						card.name = "毁坏车";
						break;
					case GoldCardType.TAKE_LIGHT:
						card.name = "毁坏灯";
						break;
					case GoldCardType.TAKE_SHOVEL:
						card.name = "毁坏铲";
						break;

				}

				return card;
			}
		}
	}
}
